<!--公共参数-->
<script th:src="@{/static/layui.js}"></script>
<script type="text/javascript" th:inline="javascript" th:fragment="ctx">
    /*<![CDATA[*/
    const ctx = /*[[@{/}]]*/ '';

    /**
     * 是否启用验证码
     * @type {boolean}
     */
    const captchaEnabled = [[${@environment.getProperty('login-captcha-enabled')}]].toLowerCase() === 'true';

    /**
     * 是否允许登录
     * @type {boolean}
     */
    const loginEnabled = [[${@environment.getProperty('login-enabled')}]].toLowerCase() === 'true';

    /**
     * 版权信息
     * @type {*[][]}
     */
    const loginCopyright = [[${@environment.getProperty('login-copyright')}]];

    console.log("%c webSql -简约而不简单 开源地址：https://gitee.com/boy_0214/websql", "color:red");


    /**
     * 获取站点配置
     * @returns {any}
     */
    function getSiteConfig() {
        let siteConfig = window.localStorage.getItem('site');
        if (siteConfig != null) {
            return JSON.parse(siteConfig);
        }
        post(ctx + "getSiteConfig", null, (res) => {
            window.localStorage.setItem("site", JSON.stringify(res.data));
            return res.data;
        });
    }


    /**
     * 数据表格返回值通用处理
     * @param res
     * @returns {{msg: *, code: number, data: *, count}}
     */
    function parseData(res) {
        return {
            "code": res.code === 200 ? 0 : 1,
            "msg": res.msg,
            "count": res.data.count,
            "data": res.data.list
        };
    }

    /**
     * 下拉框返回值通用处理
     * @param res
     * @returns {{msg: *, code: (number), data: *, count}}
     */
    function parseSelectData(res) {
        return {
            "code": res.code,
            "codeName": res.value,
            "status": res.short,
            "select": res.select == null ? 'false' : res.select
        };
    }

    /**
     * post请求
     * @param url
     * @param data
     * @param callback
     */
    function post(url, data, callback) {
        layui.use(function () {
            const $ = layui.jquery;
            const layer = layui.layer;
            var loadIndex;
            $.ajax({
                type: "post",
                url: url,
                async: true,
                data: data == null ? null : JSON.stringify(data),
                dataType: "json",
                contentType: "application/json",
                beforeSend: function () {
                    loadIndex = layer.load(2);
                },
                complete: function () {
                    layer.close(loadIndex);
                },
                success: function (result) {
                    if (typeof (callback) === "function") {
                        callback(result);
                    } else {
                        layer.msg(result.msg, {icon: 1});
                    }
                },
                error: function () {
                    if (typeof (callback) === "function") {
                        callback(false);
                    } else {
                        layer.msg("系统繁忙!", {icon: 2});
                    }
                }
            });
        });
    }

    /**
     * 弹出信息框
     * @param title  标题
     * @param content html内容
     */
    function openContent(title, content) {
        layui.use(function () {
            const $ = layui.jquery;
            const layer = layui.layer;
            layer.open({
                type: 1,
                title: title,
                shadeClose: false,
                shade: [0.3, '#000'],
                area: ['50%', '50%'],
                anim: 'slideLeft',
                isOutAnim: false,
                offset: 'auto',
                content: content
            });

        });
    }

    /**
     * 弹窗页面框
     * @param title 标题
     * @param url 地址
     */
    function openPage(title, url) {
        layui.use(function () {
            const $ = layui.jquery;
            const layer = layui.layer;
            layer.open({
                type: 2,
                title: title,
                shadeClose: false,
                shade: [0.3, '#000'],
                area: ['80%', '80%'],
                anim: 'slideLeft',
                content: url,
                isOutAnim: false,
                offset: 'auto'
            });
        });
    }

    /**
     * 弹窗页面关闭并刷新
     */
    function refresh() {
        window.parent.document.getElementById("search").click();
        const frameIndex = parent.layer.getFrameIndex(window.name);
        parent.layer.close(frameIndex);
    }


    /**
     * 发送桌面通知
     * @param message
     */
    function sendNotification(message) {
        if (getSiteConfig() !== null && getSiteConfig().enabledNotification !== undefined && getSiteConfig().enabledNotification !== 0) {
            return false;
        }
        if (window.Notification && Notification.permission === "granted") {
            new Notification("WEBSQL", {
                icon: ctx + 'static/img/inform.png',
                body: message
            });
        } else if (window.Notification && Notification.permission !== "denied") {
            Notification.requestPermission(function (status) {
                if (Notification.permission !== status) {
                    Notification.permission = status;
                }
                if (status === "granted") {
                    new Notification("WEBSQL", {
                        icon: ctx + 'static/img/inform.png',
                        body: message
                    });
                }
            });
        }
    }

    /*]]>*/
</script>




